package com.aimuceliang.aimuceliang.net;


import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * hepeng Created on 2016/9/30.
 * 类名称： RequestInterceptor
 */
public class RequestInterceptor implements Interceptor {

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request original = chain.request();
        //请求定制：添加请求头
        Request.Builder requestBuilder = original
                .newBuilder()
                .addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        //请求体定制：统一添加参数
//        if (original.body() instanceof FormBody) {
//            FormBody.Builder newFormBody = new FormBody.Builder();
//            FormBody oidFormBody = (FormBody) original.body();
//            for (int i = 0; i < oidFormBody.size(); i++) {
//                newFormBody.addEncoded(oidFormBody.encodedName(i), oidFormBody.encodedValue(i));
//            }
//            requestBuilder.method(original.method(), newFormBody.build());
//        }
        return chain.proceed(requestBuilder.build());
    }
}
